/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:焦元义
 */

import React from 'react';
import {Card, Descriptions, Drawer, Spin, Tabs} from 'antd';
import styles from '@/utils/utils.less'
import {SysDicCategoryModel} from '../data';
import HistoryLogTable from '@/components/HistoryLog';
import {getCurrentUser} from "@/utils/utils";
import {DetailsDialogProps} from "@/global";
import useLoad from "@/hooks/useLoad";
import service from "@/pages/sys/dicCategory/service";
const {TabPane} = Tabs;
const currentUser = getCurrentUser();

/** 系统字典类型详情组件 */
const SysDicCategoryDetails: React.FC<DetailsDialogProps> = props => {
  const {params: {id}, visible, hide} = props;
  const {loading, data: model} = useLoad<SysDicCategoryModel>({
    isLoad: Boolean(id),
    onLoad: () => service.selectById(id),
  }, [id]);

  return (
    <Drawer
      title="查看系统应用详细信息"
      width="50%"
      visible={visible}
      onClose={hide}
      destroyOnClose
      className={styles.drawerBodyPadding}
    >
      <Spin spinning={loading} wrapperClassName={styles.h100p}>
        <Tabs className={styles.drawerBodyTabsPadding}>
          <TabPane tab="基本信息" key="basic">
            {model && (<Basic model={model}/>)}
          </TabPane>
          <TabPane tab="操作日志" key="history">
            {model && (<HistoryLogTable tableName="SysDicCategory" primaryKey={model.id}/>)}
          </TabPane>
        </Tabs>
      </Spin>
    </Drawer>
  );
};

function Basic(props: { model: SysDicCategoryModel }) {
  const {model} = props;
  return (
    <Card bordered={false} className={styles.cardBodyDesc}>
      <Descriptions column={1} bordered={true} size="small" className={styles.detailsDescriptions}>
        {currentUser.admin && <Descriptions.Item label="字典类型主键">{model.id}</Descriptions.Item>}
        {currentUser.admin && <Descriptions.Item label="上级主键">{model.parentId}</Descriptions.Item>}
        <Descriptions.Item label="字典类型名称">{model.name}</Descriptions.Item>
        <Descriptions.Item label="字典类型编码">{model.code}</Descriptions.Item>
        <Descriptions.Item label="序号">{model.path}</Descriptions.Item>
        <Descriptions.Item label="备注">{model.remark}</Descriptions.Item>
      </Descriptions>
    </Card>
  );
}

export default React.memo(SysDicCategoryDetails);

